package com.tanhua.autoconfig;

import com.tanhua.autoconfig.properties.*;
import com.tanhua.autoconfig.template.*;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * @Author: cl
 * @Date: 2022/4/29 - 04 - 29
 * @Description:
 */
//自动装配类
@EnableConfigurationProperties({
        SmsProperties.class,
        OssProperties.class,
        AipFaceProperties.class,
        HuanXinProperties.class,
        GreenProperties.class
})//开启指定配置类(讲配置类封装的yml自动装配过来)
public class TanhuaAutoConfiguration {

    /**
     * 发送验证码bean对象
     *
     * @param smsProperties
     * @return
     */
    @Bean
    public SmsTemplate smsTemplate(SmsProperties smsProperties) {

        return new SmsTemplate(smsProperties);
    }


    /**
     * 上传照片到阿里云的bean对象
     *
     * @param ossProperties
     * @return
     */
    @Bean
    public OssTemplate ossTemplate(OssProperties ossProperties) {

        return new OssTemplate(ossProperties);
    }

    /**
     * 人脸检测
     *
     * @return
     */
    @Bean
    public AipFaceTemplate aipFaceTemplate() {

        return new AipFaceTemplate();
    }

    /**
     * 环信即时通讯
     *
     * @param properties
     * @return
     */
    @Bean
    public HuanXinTemplate huanXinTemplate(HuanXinProperties properties) {
        return new HuanXinTemplate(properties);
    }


    /**
     * 检测配置文件中，是否具有tanhua.green开头的配置
     *      同时，其中的enable属性 = true
     *   @ConditionalOnProperty：检测指定的配置是否满足要求，如果满足则执行此方法
     *   这里是检测tanhua.green下的enable选项的值是否是true
     */
    @Bean
    //@ConditionalOnProperty(prefix = "tanhua.green",value = "enable", havingValue = "true")
    public AliyunGreenTemplate aliyunGreenTemplate(GreenProperties properties) {
        return new AliyunGreenTemplate(properties);
    }
}
